﻿namespace EyeOpen.Web.Mvc
{
	using System;
	using System.Web.Mvc.Ajax;

	public static class AjaxOptionsExtensions
	{
		public static AjaxOptions Change(this AjaxOptions ajaxOptions, Action<AjaxOptions> action)
		{
			var options =
				new AjaxOptions
					{
						Confirm = ajaxOptions.Confirm,
						HttpMethod = ajaxOptions.HttpMethod,
						InsertionMode = ajaxOptions.InsertionMode,
						LoadingElementDuration = ajaxOptions.LoadingElementDuration,
						LoadingElementId = ajaxOptions.LoadingElementId,
						OnBegin = ajaxOptions.OnBegin,
						OnComplete = ajaxOptions.OnComplete,
						OnFailure = ajaxOptions.OnFailure,
						OnSuccess = ajaxOptions.OnSuccess,
						UpdateTargetId = ajaxOptions.UpdateTargetId,
						Url = ajaxOptions.Url
					};

			action(options);

			return options;
		}
	}
}